<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript 示例</title>
    <style>
        body {
            font-family: '微软雅黑', Arial, sans-serif;
            background-color: #f7f7f7;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            color: #333;
        }

        .container {
            background-color: #fff;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            padding: 30px;
            border-radius: 8px;
            width: 100%;
            max-width: 400px;
            text-align: center;
        }

        h1 {
            font-size: 28px;
            margin-bottom: 20px;
            color: #4CAF50;
        }

        .button {
            background-color: #4CAF50;
            color: white;
            font-size: 18px;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .button:hover {
            background-color: #45a049;
        }

        .output {
            margin-top: 20px;
            font-size: 16px;
            font-weight: bold;
            color: #555;
        }

        .info {
            font-size: 14px;
            color: #888;
            margin-top: 10px;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>JavaScript 合并函数示例</h1>
        <button class="button" onclick="runExample()">执行示例</button>
        <div class="output" id="output"></div>
        <div class="info">点击按钮查看函数执行结果</div>
    </div>

    <script>
        // both 函数，接受两个函数并返回一个新的函数
        const both = (f, g) => (...args) => f(...args) && g(...args);

        // 示例函数 1：判断数字是否大于 10
        const isGreaterThanTen = (num) => num > 10;

        // 示例函数 2：判断数字是否是偶数
        const isEven = (num) => num % 2 === 0;

        // 将两个函数传入 both 函数，返回一个组合后的函数
        const checkBothConditions = both(isGreaterThanTen, isEven);

        // 执行示例
        function runExample() {
            const testValue = Math.floor(Math.random() * 100); // 测试值
            const result = checkBothConditions(testValue); // 检查条件
            const outputDiv = document.getElementById('output');

            // 根据结果更新页面显示
            if (result) {
                outputDiv.innerHTML = `数字 ${testValue} 满足：大于 10 且是偶数。`;
            } else {
                outputDiv.innerHTML = `数字 ${testValue} 不满足：大于 10 且是偶数。`;
            }
        }
    </script>

</body>

</html>